{extend name="layout/default" /}


{block name="head"}
<title>编辑</title>
{/block}
{block name="content"}
<div class="ok-body">
    <!--form表单-->
    <form class="layui-form">
        <input type="hidden" name="id" value="{$info.id}">
        <div class="layui-form-item">
            <label class="layui-form-label">上级菜单</label>
            <div class="layui-input-block">
                <select name="pid">
                    <option value="0">顶级菜单</option>
                    {$menus|raw}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">菜单名称</label>
            <div class="layui-input-block">
                <input type="text" name="title" autocomplete="off" class="layui-input" lay-verify="required"
                    value="{$info.title}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">链接</label>
            <div class="layui-input-block">
                <input type="text" name="name" placeholder="模块名/控制器名/方法名" autocomplete="off" class="layui-input"
                    lay-verify="required" value="{$info.name}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">图标</label>
            <div class="layui-input-block">
                <input type="text" id="icon" name="icon" value="{$info.icon}" lay-filter="iconPicker2" class="hide">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">是否菜单</label>
            <div class="layui-input-block">
                <input type="checkbox" name="ismenu" lay-skin="switch" lay-text="是|否" {if condition="$info.ismenu eq 1"
                    } checked {/if} value="1">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|停用" {if
                    condition="$info.status eq 'normal'" } checked {/if} value="1">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">权重</label>
            <div class="layui-input-block">
                <input type="text" name="weigh" placeholder="越小越靠前" autocomplete="off" class="layui-input"
                    value="{$info.weigh}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <input type="text" name="remark" autocomplete="off" class="layui-input" value="{$info.remark}">
            </div>
        </div>
         <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="add">
                <i class="layui-icon layui-icon-ok"></i>
                {:__('Submit')}
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                {:__('Reset')}
            </button>
        </div>
    </div>
    </form>
</div>
{/block}
{block name="scripts"}
<!--js逻辑-->
<!--<script src="/static/lib/layui/lay/lay-config.js"></script>-->
<script>
    layui.use(["form", "laydate", "icon",'jquery'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let laydate = layui.laydate;
        let icon = layui.icon;

   
        icon.render({
            // 选择器，推荐使用input
            elem: "#icon",
            // fa 图标接口
            //url: "/static/css/font-awesome/less/variables.less",
            // 是否开启搜索：true/false
            search: true,
            placeholder: '',
            isSplit: true,
            // 是否开启分页
            page: true,
            // 每页显示数量，默认12
            limit: 12,
            // 点击回调
            // click: function (data) {
            //     $("#icon").val(data.field.icon)
            // },
            click: function (data) {
            },
            ready: function(d) {
            },
            // 渲染成功后的回调
            success: function (d) {
                console.log(d);
            }
        });
        //laydate.render({elem: "#birthday", type: "datetime"});

        form.verify({

        });

        form.on("submit(add)", function (data) {
               if(data.field.icon){
                        data.field.icon = 'layui-icon '+ data.field.icon;
                    }
            $.ajax(
                {
                    url:"{:url('edit')}",
                    type:"post",
                    data:data.field,
                }
                ).done(function (response) {
                //console.log(response);
                if (response.code == 1) {
                    layer.msg(response.msg,{icon:1,time:1000},function(){
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                         parent.location.reload();
                    });
                } else {
                    layer.msg(response.msg,{icon:2,time:1000},function(){

                    })
                }

            }).fail(function (error) {
                console.log(error)
            });
            return false;
        });
    });
</script>
{/block}